
#include <iostream>
#include "Hasher.h"

using namespace std;


//http://everything2.com/index.pl?node_id=1308133
/*S1, S2: unsigned 16-bit variables
S1 = 1
S2 = 0

foreach byte b in input
    S1 = (S1 + b) % 65521
    S2 = (S2 + S1) % 65521

The final checksum is S2 || S1*/
uint Hasher::simpleHash(const std::string str) {
	char c1 = 3; //representando bytes
	char c2 = 2;
	char c3 = 1;
	char c4 = 0;	
	for (uint i = 0; i<str.size(); i++) {
		c1 = (c1+str[i]) % 251; //251 - maior primo menor q 256 
		c2 = (c2+c1) % 251;
		c3 = (c3+c2) % 251;
		c4 = (c4+c3) % 251;
	}
	uint hashValue = 16777216*c4 + 65536*c3 + 256*c2 + c1; //16777216 = 2^24
	return hashValue;
}

std::string Hasher::md5(const std::string) {
	return "MC SUGA!!!";
}
